package com.admin.web.controller;

import com.bayss.core.constant.ResultMsg;
import com.bayss.core.entity.station.Station;
import com.bayss.core.service.address.AddressService;
import com.bayss.core.service.station.StationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 配送站
 *
 * @author yangjian
 */
@Slf4j
@RestController
public class StationAdminController extends ApiBaseController{

    private final StationService stationService;

    private final AddressService addressService;

    @Autowired
    public StationAdminController(StationService stationService, AddressService addressService) {
        this.stationService = stationService;
        this.addressService = addressService;
    }

    /**
     * 添加配送站
     * @return
     */
    @RequestMapping("/station/save.json")
    public ResultMsg addStation(@RequestBody Station station) {
        if (station.getId() != null && station.getId() != 0) {
            return ResultMsg.success( stationService.update(station));
        }
        return ResultMsg.success(stationService.save(station));
    }

    /**
     * 删除配送
     * @return
     */
    @RequestMapping("/station/del.json")
    public ResultMsg del(@RequestParam(name = "stationId") Long id) {
        return ResultMsg.success( stationService.del(id));
    }

    /**
     * 获取配送
     * @return
     */
    @RequestMapping("/station/get.json")
    public ResultMsg get() {
        return ResultMsg.success( stationService.get());
    }

    /**
     * 维护
     * @return
     */
    @RequestMapping("/station/enable.json")
    public ResultMsg enable(@RequestParam(name = "stationId") Long id) {
        return ResultMsg.success(stationService.enable(id));
    }

    /**
     * 恢复
     * @return
     */
    @RequestMapping("/station/resume.json")
    public ResultMsg resume(@RequestParam(name = "stationId") Long id) {
        return ResultMsg.success(stationService.resume(id));
    }

    /**
     * 设置配送规则
     * @return
     */
    @RequestMapping("/station/rule/save.json")
    public ResultMsg saveSendPriceRule(@RequestBody Station station) {
        return ResultMsg.success( stationService.update(station));
    }

}
